<template>
  <!--优秀案例提报新增  -->
  <div>
    <div>
      <FormPanel
        ref="formPanel"
        :list="initForm"
        :cols="2"
        :formType="type"
        :labelWidth="130"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
      />
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
    </div>

    <!-- 项目详情弹窗 -->
    <BaseDialog
      title="项目详情查询"
      :visible.sync="visibleProjectPlanDetail"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <info v-model="initData" ref="projectPlanDetailDialog" @close="closeprojectPlanDetail" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { addOutStandingCase, updateOutStandingCase, getPlanById } from '@/api/cms-api/projectOperating/case/oemCollect/index';
import caseCollectMadal from '../departmentReport/caseCollectMadal';
import info from '../../summary/oemInquire/info';
export default {
  mixins: [dictionary],
  components: {
    caseCollectMadal,
    info
  },
  props: {
    type: {
      type: String,
      required: true
    },
    rowEditData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {},
      visibleCaseCollect: false,
      visibleProjectPlan: false,
      caseLevyId: '', //案例征集ID
      caseUrlList: [],
      columns: this.creatHeader(), //历史审核记录表头
      isSelectColumn: false,
      fetchApi: '', //ipa 接口
      fetchParams: {}, //参数
      visibleProjectPlanDetail: false
    };
  },
  mounted() {
    // console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    closeprojectPlanDetail(data) {
      this.visibleProjectPlanDetail = false;
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '项目审核部门',
          dataIndex: 'businessId',
          sorter: true
        },
        {
          title: '项目审核人',
          dataIndex: 'title1',
          sorter: true
        },
        {
          title: '经销商简称',
          dataIndex: 'title2',
          sorter: true
        },
        {
          title: '审核状态',
          dataIndex: 'caseStatus',
          sorter: true,
          filterItems: this.createDictList('1416'),
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.caseStatus, '1416')}</span>;
          }
        },
        {
          title: '审核时间',
          dataIndex: 'levyStartDate',
          sorter: true,
          render: props => {
            return <span>{this.formatDates(props.row.levyStartDate)} </span>;
          }
        },
        { title: '驳回原因', dataIndex: 'caseLevyClaim', sorter: true }
      ];
    },
    init() {
      // 更新接口需要的记录 ID
      // debugger;
      this.caseId = this.rowEditData.caseId;
      this.caseLevyId = this.rowEditData.caseLevyId;
      this.planId = this.rowEditData.planId;
      // console.log(this.rowEditData);
      this.initForm.forEach(x => {
        x.initialValue = this.rowEditData[x.fieldName];
      });
    },
    reqRepairDealer(val) {
      this.initForm[1].initialValue = val.caseLevyCode;
      this.initForm[2].initialValue = val.caseLevyName;
      this.initForm[3].initialValue = val.levyStartDate;
      this.initForm[4].initialValue = val.levyEndDate;
      this.initForm[5].initialValue = val.projectExecuteStartDate;
      this.initForm[6].initialValue = val.projectExecuteEndDate;
      this.initForm[7].initialValue = val.caseLevyClaim;
      this.initForm[8].initialValue = val.collectFile;
      this.caseLevyId = val.caseLevyId;
      this.visibleCaseCollect = false;
    },
    //关闭案例征集弹框
    goBackRepairDealer() {
      this.visibleCaseCollect = false;
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'INPUT',
          label: '优秀案例编号',
          fieldName: 'caseCode',
          initialValue: '系统自动生成',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '案例征集编号',
          fieldName: 'caseLevyCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '案例征集名称',
          fieldName: 'caseLevyName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '征集开始日期',
          fieldName: 'levyStartDate',
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '征集结束日期',
          fieldName: 'levyEndDate',
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '项目执行开始日期',
          fieldName: 'projectExecuteStartDate',
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '项目执行结束日期',
          fieldName: 'projectExecuteEndDate',
          initialValue: '',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '方案征集要求及说明',
          fieldName: 'caseLevyClaim',
          initialValue: '',
          rows: 4,
          selfCols: 2,
          disabled: true
        },
        {
          type: 'UPLOAD_FILE',
          label: '征集附件',
          disabled: true,
          fieldName: 'collectFile',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商简称',
          fieldName: 'dealerShortname',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '事业部',
          fieldName: 'orgName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '项目编号',
          fieldName: 'planCode',
          placeholder: '请选择',
          initialValue: '',
          readonly: true,
          unitRender: () => {
            return (
              <div>
                <el-button slot="append" icon="el-icon-document" onClick={() => this.planDetailDialog()}>
                  详情
                </el-button>
              </div>
            );
            // return <el-button slot="append" icon="el-icon-search" onClick={() => this.openProjectPlanDialog()}></el-button>;
          }
        },
        {
          type: 'INPUT',
          label: '项目名称',
          fieldName: 'projectName',
          initialValue: '',
          rows: 4,
          disabled: true
        },
        {
          type: 'UPLOAD_FILE',
          label: '项目附件',
          disabled: true,
          fieldName: 'projectFile',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          initialValue: '',
          rows: 4,
          selfCols: 2,
          disabled: true,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '评选建议',
          fieldName: 'selectionSuggest',
          initialValue: '',
          rows: 4,
          selfCols: 2,
          disabled: true,
          placeholder: ''
        }
      ];
    },
    //打开项目详情弹窗
    async planDetailDialog() {
      this.planDetailLoading = true;
      // let param = { planId: this.planId };
      if (this.planId != null) {
        let res = await getPlanById(this.planId);
        if (res.resultCode === 200) {
          this.planDetailLoading = false;
          this.planRow = res.data;
        }
        this.initData = {
          row: this.planRow,
          type: 'show' //add/edit/show
        };
        this.visibleProjectPlanDetail = true;
      } else {
        this.$notify.warning({ title: '提示信息', message: '请先查询选择项目！' });
      }
    },
    formChangeHandle(val) {
      this.formValue = val;
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    //打开案例征集弹窗
    openCaseCollectDialog() {
      this.visibleCaseCollect = true;
    },
    //打开项目计划弹窗
    openProjectPlanDialog() {
      this.visibleProjectPlan = true;
    },
    closecaseCollect(data) {
      this.visibleCaseCollect = data.visible;
      this.initForm[1].initialValue = '';
    },
    closeprojectPlan(data) {
      this.visibleProjectPlan = data.visible;
      this.initForm[8].initialValue = '';
    },
    formatDates: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + '-' + month + '-' + day;
    }
  },
  created() {
    this.init();
  }
};
</script>
